import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class DataGenerator {
    public static void main(String[] args) {
        try {
            generate(10000);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 产生一个由大写字母构成的长度为length的随机字符串
     *
     * @param length 字符串的长度
     * @return 产生的字符串
     */
    @org.jetbrains.annotations.NotNull
    public static String getRandomString(int length) {
        String template = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        StringBuilder buffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            char c = template.charAt(random.nextInt(26));
            buffer.append(c);
        }
        return buffer.toString();
    }

    /**
     * 产生一个由0~9数字构成的长度为length的随机字符串
     *
     * @param length 字符串的长度
     * @return 产生的字符串
     */
    @org.jetbrains.annotations.NotNull
    public static String getRandomNumber(int length) {
        StringBuilder buffer = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            int num = random.nextInt(10);
            buffer.append(num);
        }
        return buffer.toString();
    }

    /**
     * 产生一个数据文件data.csv
     * 因为格式很简单，所以没有使用openCSV
     *
     * @param num 数据的行数
     * @throws IOException 读写异常
     */
    public static void generate(int num) throws IOException {
        Random random = new Random(114514);
        FileWriter writer = new FileWriter("data.csv");
//        Data[] data = new Data[num];
        ArrayList<Data> data = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            data.add(new Data(i, getRandomString(12)));
        }
        Collections.shuffle(data);
        for (int i = 0; i < num; i++) {
            writer.write(data.get(i).key + ", " + data.get(i).data + "\n");
        }


        writer.close();
    }
}